package com.bishe.demo.modules.other.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.common.entity.SearchBean;
import com.bishe.demo.modules.other.entity.Travel;
import com.bishe.demo.modules.other.service.TravelService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class TravelController {
    @Autowired
    private TravelService travelService;

    @PostMapping(value = "/travel", consumes = "application/json")
    ResultEntity<Travel> insertTravel(@RequestBody Travel travel) {
        return travelService.insertTravel(travel);
    }

    @PutMapping(value = "/travel")
    ResultEntity<Travel> updateTravel(@RequestBody(required = true) Travel travel) {
        return travelService.updateTravel(travel);
    }

    @DeleteMapping("/travel/{travelId}")
    ResultEntity<Travel> deleteTravelByTravelId(@PathVariable int travelId) {
        return travelService.deleteTravelByTravelId(travelId);
    }

    @GetMapping("/travel/{travelId}")
    Travel getTravelByTravelId(@PathVariable int travelId) {
        return travelService.getTravelByTravelId(travelId);
    }

    @PostMapping(value = "/travels", consumes = "application/json")
    PageInfo<Travel> getTravelBySearchBean(@RequestBody SearchBean searchBean) {
        return travelService.getTravelBySearchBean(searchBean);
    }
}
